<template>
  <div class="view-container">

    <table-search-view :search-items="searchItems" :table-items="tableItems" :search-function="search">
      <template slot="action" slot-scope="scope">
        <action-renew-info :action="false" :scope="scope"></action-renew-info>
        <action-info v-if="scope.row.state==='relet'" :scope="scope" :scopeId="'reletNumber'">续租订单详情</action-info>
        <action-info :scope="scope">原订单详情</action-info>
      </template>
    </table-search-view>

  </div>
</template>

<script>
  import TableSearchView from '@/components/TableSearchView';

  import actionOrderInfo from './components/actionOrderInfo.vue';
  import actionRenewInfo from './components/actionRenewInfo.vue';

  import {getOrderRenewList} from '@/api/order';

  export default {
    name: 'renewRecode', /*续租记录*/
    components: {
      'table-search-view':TableSearchView,
      'action-info':actionOrderInfo,
      'action-renew-info':actionRenewInfo,
    },
    data ()
    {
      return {
        searchItems: [
          {
            label: '商品名称',
            type: 'autocomplete',
            placeholder:'请输入商品名称',
            model:'goodsName',
          },
          {
            label: '续租开始时间',
            type: 'datetimerange',
            placeholder:'请选择续租开始时间',
            model:'timeRange',
          },
          {
            label: '续租申请单编号',
            type: 'input',
            placeholder:'请输入续租申请单编号',
            model:'reletNumber',
          },
          {
            label: '下单用户',
            type: 'input',
            placeholder:'请输入下单用户',
            model:'userName',
          },
          {
            label: '申请结果',
            type: 'select',
            placeholder:'请选择申请结果',
            model:'state',
            multiple:false,
            filterable:false,
            options:[
              {
                label:'全部结果',
                value:'',
              },{
              label:'同意续租',
              value:'relet',
            },
              {
                label:'不同意续租',
                value:'not_relet',
              }]
          },
        ],
        tableItems:[
          {
            label:'续租申请单编号',
            prop:'reletNumber',
            width:'180px;',
          },
          {
            label:'关联订单编号',
            prop:'orderNumber',
            width:'180px;',
          },
          {
            label:'商品名称',
            prop:'goodsName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'下单用户',
            prop:'userName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'续租开始时间',
            prop:'reletStartTime',
            width:'160px;',
            formatter:'parseTime',
            sortable:true,
          },
          {
            label:'申请结果',
            prop:'checkStateStr',
            width:'120px;',
            sortable:true,
          },
          {
            label:'续租订单状态',
            prop:'stateStr',
            width:'160px;',
            sortable:true,
          },
          {
            type:'scope',
            label:'操作',
            slot:'action',
            width:'300px;',
          },
          {

          }
        ],
      }
    },
    methods: {
      search(data)
      {
        data.tab='history';
        return getOrderRenewList(data);

        /*return new Promise(resolve => {
          let resp = {data:{total:10, list:[
            {
              "id": 1,
              "reletNumber": "XZ5467945458787",
              "orderNumber": "201712652367846854",
              "goodsName": "IphoneX",
              "userName": "17682311195",
              "leaseExpireTime": 1511932806661,
              "clearanceTime": 1511931748392,
              "status": "check",
              "stateStr": "租赁中"
            },
            {
              "id": 1,
              "reletNumber": "XZ5467945458787",
              "orderNumber": "201712652367846854",
              "goodsName": "IphoneX",
              "userName": "17682311195",
              "leaseExpireTime": 1511932830851,
              "clearanceTime": 1511932056742,
              "status": "check",
              "stateStr": "租赁中"
            },
            {
              "id": 1,
              "reletNumber": "XZ5467945458787",
              "orderNumber": "201712652367846854",
              "goodsName": "IphoneX",
              "userName": "17682311195",
              "leaseExpireTime": 1511930950750,
              "clearanceTime": 1511931478588,
              "status": "check",
              "stateStr": "租赁中",
              "state":"relet"
            }
          ]}};

          resolve(resp);
        });*/

      }
    }
  }
</script>
